package com.ninong.ker.common.annotation.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 校验工具类
 * @author cmd
 */
public class PatternUtil {

    /**
     * 非空校验
     * @author cmd
     * @Date 2020/6/8 11:26
     * @version 1.0
     */
    public static boolean isEmpty(Object o){
        return (null==o || ValidateConstant.EMPTY.equals(o) || ValidateConstant.NULL.equals(o)) ;
    }

    /**
     * 校验身份证
     * @author cmd
     * @Date 2020/6/8 14:54
     * @version 1.0
     */
    public static PatternResult regexIdCard(String regexStr){
        PatternResult result = new PatternResult();
        result.setResult(IDCardNumberUtil.validateIdCardNumber(regexStr));
        result.setMsg(IDCardNumberUtil.exMsg);
        return result;
    }

    /**
     * 校验邮箱
     * @author cmd
     * @Date 2020/6/8 16:03
     * @version 1.0
     */
    public static boolean patternEmail(String regexStr){
       return pattern(ValidateConstant.EX_EMAIL,regexStr);
    }

    /**
     * 校验座机号、传真号
     * @author cmd
     * @Date 2020/6/8 16:37
     * @version 1.0
     */
    public static boolean pattenTel(String regexStr){
        return pattern(ValidateConstant.EX_TEL,regexStr)||pattern(ValidateConstant.EX_TEL_QH,regexStr);
    }

    /**
     * 校验手机号
     * @author cmd
     * @Date 2020/6/8 17:16
     * @version 1.0
     */
    public static boolean patternMobile(String regexStr){
        return pattern(ValidateConstant.EX_MOBILE,regexStr);
    }

    /**
     *@Description 校验数字
     *@author cmd
     *@Date 2020-12-13 18:17
     *@Param
     *@return
     */
    public static boolean patternNumber(String regexStr) {
        return pattern(ValidateConstant.EX_NUMBER,regexStr);
    }

    /**
     * 正则校验
     * @author cmd
     * @Date 2020/6/8 14:48
     * @version 1.0
     */
    public static boolean pattern(String regexExpre ,String regexStr){
        Pattern pattern = Pattern.compile(regexExpre);
        Matcher matcher = pattern.matcher(regexStr);
        return matcher.matches();
    }

}
